﻿using Microsoft.Extensions.DependencyInjection;

namespace Ioc1
{
  internal class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello, World!");
      ServiceCollection services = new ServiceCollection();
      
      services.AddScoped<ITestServices, TestServices>();
      using (ServiceProvider sp = services.BuildServiceProvider())
      {
        var se = sp.GetService<ITestServices>();
        var reqs = sp.GetRequiredService<ITestServices>();
        se.Name = "Lili";
        se.SayHello();
      }
      Console.ReadLine();
    }
  }

  interface ITestServices
  {
    string Name { get; set; }
    void SayHello();
  }
  class TestServices : ITestServices
  {
    public string Name { get; set; }

    public void SayHello()
    {
      Console.WriteLine($"{Name} 说 Hello!");
    }
  }
}